package com.itheima.web.controller;

import com.itheima.domain.Comment;
import com.itheima.domain.Movies;
import com.itheima.service.CommentService;
import com.itheima.service.MoviesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SingleController {

    @Autowired
    private MoviesService moviesService;

    @Autowired
    private CommentService commentService;

    // 查询影视详情
    @GetMapping("/single/findMoviesById")
    public Movies findMoviesById(Integer id) {
        return moviesService.findById(id);
    }

    // 查询影视评论
    @GetMapping("/single/findCommentListByMoviesId")
    public List<Comment> findCommentListByMoviesId(Integer moviesId) {
        return commentService.findCommentListByMoviesId(moviesId);
    }

    // 发表评论
    @PostMapping("/single/saveComment")
    public String saveComment(@RequestBody Comment comment) {
        commentService.saveComment(comment);

        return "ok";
    }
}
